from haystack import indexes

from .models import Recruit


class RecruitIndex(indexes.SearchIndex, indexes.Indexable):

    text = indexes.CharField(document=True, use_template=True)
    city = indexes.CharField(model_attr='city')
    id = indexes.IntegerField(model_attr='id')
    jobname = indexes.CharField(model_attr='jobname')
    salary = indexes.CharField(model_attr='salary')
    condition = indexes.CharField(model_attr='condition')
    education = indexes.CharField(model_attr='education')
    type = indexes.CharField(model_attr='type')
    createtime = indexes.CharField(model_attr='createtime')
    labels = indexes.CharField(model_attr='labels')
    enterprise = indexes.IntegerField(model_attr='enterprise_id')

    def get_model(self):
        """返回建立索引的模型类"""
        return Recruit

    def index_queryset(self, using=None):
        """返回要建立索引的数据查询集"""
        # print(self.get_model().objects.all())
        return self.get_model().objects.all()